package com.payment.common.utils.pay;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

public class SortUtil {

    @SuppressWarnings({ "rawtypes", "unchecked" })
	public static String getSortString(Map pro){
        List<String> sortKeys= new ArrayList<String>(pro.keySet());
        Collections.sort(sortKeys);
        StringBuilder builder=new StringBuilder();
        for(String key:sortKeys){
            builder.append(pro.get(key));
        }
        return builder.toString();
    }


	/**
	 * 消息头设置Sing
	 * 
	 * @param token
	 * @param sercetKey
	 * @throws Exception 
	 */
	public static String getSign(String token, Map<String, String> params, String sercetKey)  {
		
		String orderStr = SortUtil.getSortString(params);
		return token.equals("") ? EncryptUtil.md5Encrypt(orderStr + sercetKey)
				: EncryptUtil.md5Encrypt(orderStr + token + sercetKey);
	}
}
